package com.duoec.dw.lineage.service.analyser.statement;

import com.duoec.dw.lineage.dto.statement.DropSqoopStatement;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xuwenzhen
 */
@Service
public class CommentSqoopStatementAnalyser extends BaseSqoopStatementAnalyser<DropSqoopStatement> {
    private static final String COMMENT_PREFIX1 = "-";
    private static final String COMMENT_PREFIX2 = "#";
    private static final String STR_MYSQL = "mysql";
    private static final String STR_VERTICA = "vertica";

    /**
     * 检查当前行是否需要当前分析器处理
     *
     * @param line 当前行
     * @return true，则会使用analyse方法解析
     */
    @Override
    public boolean check(String line) {
        if (line.length() == 0 || line.startsWith(COMMENT_PREFIX1) || line.startsWith(COMMENT_PREFIX2)) {
            return true;
        }
        String lowerCaseStr = line.toLowerCase();
        return lowerCaseStr.startsWith(STR_MYSQL) || lowerCaseStr.startsWith(STR_VERTICA);
    }

    /**
     * 解析脚本，并返回当前的语句
     *
     * @param lines 所有行
     * @param index 开始行，0开始
     * @return 当前语句
     */
    @Override
    public DropSqoopStatement analyse(List<String> lines, int index) {
        return null;
    }
}
